﻿var store1_0 = Ext.create('Ext.data.Store', {
    storeId: 'runoff_store0',
    fields: ['stationNum', 'stationName', 'stationType', 'startTime', 'endTime', 'comment'],
    data:{}
});
var store1_1 = Ext.create('Ext.data.Store', {
    storeId: 'runoff_store1',
    fields: ['stationName', 'YEAR', 'AVQ'],
    data:{}
});

var store1_2 = Ext.create('Ext.data.Store', {
    storeId: 'runoff_store2',
    fields: ['paramName', 'paramValue', 'paramExplain'],
    data: [
        {
            paramName: '参数w',
            paramValue: '3.163',
            paramExplain: ''
        }]
});

var store1_3 = Ext.create('Ext.data.Store', {
    storeId: 'runoff_store3',
    fields: ['month', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6'],
    data: [
        { "month": "1月", "p1": "95.7", "p2": "116.6", "p3": "-17.9", "p4": "130.9", "p5": "-26.8", "p6": "枯水" },
        { "month": "2月", "p1": "305.2", "p2": "154.0", "p3": "98.2", "p4": "188.1", "p5": "62.2", "p6": "丰水" },
        { "month": "3月", "p1": "174.1", "p2": "347.1", "p3": "-49.8", "p4": "338.9", "p5": "-48.6", "p6": "枯水" },
        { "month": "4月", "p1": "185.9", "p2": "401.1", "p3": "-53.7", "p4": "462.7", "p5": "-59.8", "p6": "枯水" },
        { "month": "5月", "p1": "583.2", "p2": "209.6", "p3": "178.2", "p4": "494.3", "p5": "18.0", "p6": "偏丰" },
        { "month": "6月", "p1": "734.5", "p2": "384.2", "p3": "91.2", "p4": "673.7", "p5": "9.0", "p6": "平水" },
        { "month": "7月", "p1": "264.0", "p2": "96.2", "p3": "174.5", "p4": "357.8", "p5": "-26.2", "p6": "枯水" },
        { "month": "8月", "p1": "139.3", "p2": "116.0", "p3": "20.1", "p4": "222.7", "p5": "-37.5", "p6": "枯水" },
        { "month": "9月", "p1": "149.9", "p2": "95.6", "p3": "56.9", "p4": "176.0", "p5": "-14.8", "p6": "偏枯" },
        { "month": "10月", "p1": "153.8", "p2": "67.8", "p3": "126.9", "p4": "146.2", "p5": "5.2", "p6": "平水" },
        { "month": "11月", "p1": "101.9", "p2": "63.6", "p3": "60.4", "p4": "165.7", "p5": "-38.5", "p6": "枯水" },
        { "month": "12月", "p1": "84.1", "p2": "63.6", "p3": "32.4", "p4": "140.3", "p5": "-40.0", "p6": "枯水" },
        { "month": "全年", "p1": "247.6", "p2": "176.3", "p3": "40.5", "p4": "291.4", "p5": "-15.0", "p6": "偏枯" }
    ]
});

var yearStore = Ext.create("Ext.data.Store", {
    fields: ["year", "Value"],
    data: [
        { year: "2010", Value: 2010 },
        { year: "2011", Value: 2011 },
        { year: "2012", Value: 2012 },
        { year: "2013", Value: 2013 },
        { year: "2014", Value: 2014 },
        { year: "2015", Value: 2015 },
        { year: "2016", Value: 2016 },
        { year: "2017", Value: 2017 },
    ]
});


var svcMedTypeStore = new Ext.data.JsonStore({
    fields: ['name', 'value'],
    data: [{ name: '1', value: '已有方案' },
    { name: '2', value: '统计模型' },
    { name: '3', value: '水文模型' }]
});

var svcMedTypeCombo = new Ext.form.ComboBox({
    store: svcMedTypeStore,
    valueField: 'value',
    displayField: 'name',
    mode: 'local',
    forceSelection: true,
    editable: false,
    triggerAction: 'all',
    selectOnFocus: true
});

var runoffTabpanelId = null;

Ext.define('Admin.view.runoff.RunoffTabPanel', {
    extend: 'Ext.tab.Panel',
    alias: 'widget.runoffTabPanel',
    xtype: 'runoffTabPanel',
    cls: 'mytab2-panel',
    border: false,
    initComponent: function () {
        var me = this;
        runoffTabpanelId = new Date().getTime() + '-runoffTabpanel';
        var items = [{
            title: '径流数据',
            layout: {
                type: 'vbox',
                align: 'stretch'
            },
            items: [{
                xtype: 'grid',
                height: 200,
                reference: 'runoff_store0_table',
                margin: '10 10 0 10',
                style: 'border: 1px solid #ccc',
                // scroll: false,
                // reference: 'baseLifeTable',
                loadMask: true,
                stripeRows: true,
                columnLines: true,
                forceFit: true, //表格自适应
                columns: [{
                    header: '站点编号',
                    dataIndex: 'stationNum',
                    editor: 'textfield',
                    align: 'center'
                }, {
                    header: '站点名称',
                    dataIndex: 'stationName',
                    editor: 'textfield',
                    align: 'center'
                }, {
                    header: '站点类型',
                    dataIndex: 'stationType',
                    editor: 'textfield',
                    align: 'center'
                }, {
                    header: '开始时间',
                    dataIndex: 'startTime',
                    editor: 'textfield',
                    align: 'center'
                }, {
                    header: '结束时间',
                    dataIndex: 'endTime',
                    editor: 'textfield',
                    align: 'center'
                }, {
                    header: '备注',
                    dataIndex: 'comment',
                    editor: 'textfield',
                    align: 'center'
                }],
                listeners: {
                    rowclick: 'changeStationName'
                },
                store: Ext.data.StoreManager.lookup('runoff_store0'),
            }, {
                flex: 1,
                layout: {
                    type: 'hbox',
                    align: 'stretch'
                },
                items: [{
                    flex: 1,
                    xtype: 'panel',
                    listeners: {
                        resize: 'buildTab2Chart'
                    }
                }, {
                    xtype: 'grid',
                    flex: 1,
                    margin: 10,
                    style: 'border: 1px solid #ccc',
                    // scroll: false,
                    // reference: 'baseLifeTable',
                    loadMask: true,
                    stripeRows: true,
                    columnLines: true,
                    // forceFit: true, //表格自适应
                    listeners: {
                        rowclick: 'changeMonthData'
                    },
                    columns: [{
                        header: '站点',
                        dataIndex: 'stationName',
                        editor: 'textfield',
                        align: 'center',
                        flex: 1
                    }, {
                        header: '时间',
                        dataIndex: 'YEAR',
                        editor: 'textfield',
                        align: 'center',
                        flex: 1
                    }, {
                        header: '水量（亿m³）',
                        dataIndex: 'AVQ',
                        editor: 'textfield',
                        align: 'right',
                        flex: 1
                    }],
                    store: Ext.data.StoreManager.lookup('runoff_store1'),
                }]
            }]
        }, {
            title: '预报结果',
            layout: {
                type: 'vbox',
                align: 'stretch'
            },
            items: [{
                xtype: 'grid',
                height: 200,
                autoScroll: true,
                margin: 10,
                reference: 'wdTab3Grid1',
                loadMask: true,
                stripeRows: true,
                columnLines: true,
                // forceFit: true, //表格自适应
                style: 'border: 1px solid #ccc',
                columns: [{
                    text: '月份',
                    dataIndex: 'month',
                    editor: 'textfield',
                    align: 'right',
                    flex: 1
                }, {
                    text: '预报径流量',
                    dataIndex: 'p1',
                    editor: 'textfield',
                    align: 'right',
                    flex: 1
                }, {
                    text: '上一年径流量',
                    dataIndex: 'p2',
                    editor: 'textfield',
                    align: 'right',
                    flex: 1
                }, {
                    text: '同比',
                    dataIndex: 'p3',
                    editor: 'textfield',
                    align: 'right',
                    renderer: 'renderColor',
                    flex: 1
                }, {
                    text: '多年平均',
                    dataIndex: 'p4',
                    editor: 'textfield',
                    align: 'right',
                    flex: 1
                }, {
                    text: '距平',
                    dataIndex: 'p5',
                    editor: 'textfield',
                    align: 'right',
                    renderer: 'renderColor',
                    flex: 1
                }, {
                    text: '结论',
                    dataIndex: 'p6',
                    editor: 'textfield',
                    align: 'center',
                    flex: 1
                }],
                store: Ext.data.StoreManager.lookup('runoff_store3')//store
                // plugins: {
                //     ptype: 'cellediting',
                //     clicksToEdit: 1
                // }
            }, {
                flex: 1,
                layout: {
                    type: 'hbox',
                    align: 'stretch'
                },
                items: [{
                    flex: 1,
                    xtype: 'panel',
                    listeners: {
                        resize: 'buildTab3Chart1'
                    }
                }, {
                    flex: 1,
                    xtype: 'panel',
                    listeners: {
                        resize: 'buildTab3Chart2'
                    }
                }]
            }]
        }];
        me.items = items;
        me.id = runoffTabpanelId;
        this.callParent(arguments);
    }
});

// Ext.getCmp("welcomeGrid").headerCt.getGridColumns()[1].autoSize();

Ext.define('Admin.view.runoff.Runoff', {
    extend: 'Ext.panel.Panel',
    xtype: 'runoff',
    requires: ['Admin.view.runoff.RunoffController'],
    controller: 'runoffController',
    height: '100%',
    layout: {
        type: 'hbox',
        align: 'stretch'
    },
    items: [{
        xtype: 'panel',
        flex: 1,
        margin: '0 5 0 0',
        layout: {
            type: 'vbox',
            align: 'stretch'
        },
        items: [{
            xtype: 'grid',
            height: 310,
            cls: 'mytab2-panel',
            loadMask: true,
            stripeRows: true,
            columnLines: true,
            // forceFit: true,
            plugins: ['cellediting', 'gridfilters'],
            listeners: {
                'rowclick': 'clickRunoffTab2Chart'
            },
            columns: [{
                header: '来水区间',
                dataIndex: 'comeWater',
                // editor: 'textfield',
                align: 'center',
                style: 'background: #EEEEEE',
                flex: 5
            }, {
                header: '预报方式',
                dataIndex: 'forecastType',
                // editor:svcMedTypeCombo,
                editor: new Ext.form.field.ComboBox({
                    typeAhead: true,
                    triggerAction: 'all',
                    store: [
                        ['已有方案▼', '已有方案'],
                        ['统计模型▼', '统计模型'],
                        ['水文模型▼', '水文模型']
                    ],
                    listeners: {
                        'select': 'changeRunoffTab2Chart',
                    }
                }),
                align: 'center',
                style: 'background: #EEEEEE',
                flex: 7
            }, {
                header: '状态',
                dataIndex: 'status',
                // editor: 'textfield',
                align: 'center',
                style: 'background: #EEEEEE',
                flex: 4
            }],
            store: {
                fields: ['comeWater', 'forecastType', 'status'],
                data: [  {
                    comeWater: '沙子岭',
                    forecastType: '统计模型▼',
                    status: '未完成'
                },{
                    comeWater: '洪门以上',
                    forecastType: '统计模型▼',
                    status: '未完成'
                }, {
                    comeWater: '南城',
                    forecastType: '统计模型▼',
                    status: '未完成'
                },{
                    comeWater: '廖坊以上',
                    forecastType: '已有方案▼',
                    status: '未完成'
                }, {
                    comeWater: '廖家湾以上',
                    forecastType: '统计模型▼',
                    status: '未完成'
                },{
                    comeWater: '娄家村以上',
                    forecastType: '统计模型▼',
                    status: '未完成'
                }, {
                    comeWater: '李家渡以上',
                    forecastType: '统计模型▼',
                    status: '未完成'
                }]
            }
        },
        {
            flex: 1,
            margin: '10 0 0 0',
            xtype: 'tabpanel',
            height: 200,
            width: '100%',
            cls: 'mytab2-panel',
            border: false,
            items: [{
                title: '预报模型参数',
                items: [{
                    xtype: 'panel',
                    // layout: 'fit',
                    bodyStyle: 'height:20%;',
                    // autoHeight: true,
                    items: [{
                        margin: 10,
                        //html: '<div id="forecastModel">预报模型：水均衡模型</div>'
                        html: '<div id="forecastModel">预报模型：灰色统计模型</div>'
                    }, {
                        xtype: 'grid',
                        height: 160,
                        autoScroll: true,
                        reference: 'baseLifeTable',
                        loadMask: true,
                        stripeRows: true,
                        columnLines: true,
                        // forceFit: true, //表格自适应
                        columns: [{
                            header: '参数名称',
                            dataIndex: 'paramName',
                            editor: 'textfield',
                            align: 'center',
                            style: 'background: #EEEEEE',
                            flex: 1
                        }, {
                            header: '参数值',
                            dataIndex: 'paramValue',
                            editor: 'textfield',
                            align: 'center',
                            style: 'background: #EEEEEE',
                            flex: 1
                        }, {
                            header: '参数说明',
                            dataIndex: 'paramExplain',
                            editor: 'textfield',
                            align: 'center',
                            style: 'background: #EEEEEE',
                            flex: 1
                        }],
                        store: Ext.data.StoreManager.lookup('runoff_store2')//store

                    }, {
                            xtype: 'panel',
                            height: 30,
                            layout: 'center',
                            loadMask: true,
                            forceFit: true,
                            items: [{
                                align: 'center',
                                xtype: 'button',
                                text: '开始预报',
                                listeners: {
                                    click: 'initTest'
                                }
                            }]
                        }]
                }]
            }, {
                title: '已有成果选择',
                items: [{
                    xtype: 'tabpanel',
                    width: '100%',
                    cls: 'mytab2-panel',
                    tabBar: {
                        cls: 'mytab2',
                        style: 'border-bottom:1px solid #2A95C5 !important'
                    },
                    items: [{
                        title: '数据库',
                        items: [{
                            xtype: 'panel',
                            // layout: 'fit',
                            bodyStyle: 'height:20%;',
                            // autoHeight: true,
                            style: 'border:1px solid #ccc;' +
                            'filter: progid:DXImageTransform.Microsoft.Shadow(color=#CCCCCC, strength=4);' +
                            '-moz-box-shadow: 0 0 5px #CCCCCC;' +
                            '-webkit-box-shadow: 0 0 5px #CCCCCC;' +
                            'box-shadow: 0 0 5px #CCCCCC;',
                            items: [{/*
                                html: '<div class="col-md-12"><span>方案年份：</span><span><select name="year"><option value="2011">2011</option><option value="2012">2012</option><option value="2013">2013</option><option value="2014">2014</option></select></span><span>-</span><span><select name="year"><option value="2011">2011</option><option value="2012">2012</option><option value="2013">2013</option><option value="2014">2014</option></select></span><span>&nbsp;<input type="button" value="查询"  cls: "x-btn-text-icon" /> </span></div>'
                            */
                                layout:'column',
                                title: '方案年份:',
                                // cls:'white_column',
                                items: [ {
                                    xtype: "combobox",
                                    margin: 2,
                                    name: "year",
                                    store: yearStore,
                                    editable: false,
                                    displayField: "year",
                                    valueField: "Value",
                                    emptyText: "选择",
                                    queryMode: "local",
                                    columnWidth: 0.3
                                },{

                                    html:'<div style="height:30px;line-height:30px">——</div>',
                                    columnWidth: 0.1},{
                                    xtype: "combobox",
                                    margin: 2,
                                    name: "year",
                                    store: yearStore,
                                    editable: false,
                                    displayField: "year",
                                    valueField: "Value",
                                    emptyText: "选择",
                                    queryMode: "local",
                                    columnWidth: 0.3
                                },{
                                        xtype:'button',
                                        margin: 2,
                                        text: '查询',
                                        style: {
                                        background  : 'lightgreen'
                                        },
                                        renderTo: Ext.getBody(),
                                        columnWidth: 0.2
                                }],
                                renderTo: Ext.getBody()
                            }, {
                                xtype: 'grid',
                                height: '40%',
                                margin: '5,0,0,0',
                                autoScroll: true,
                                reference: 'baseLifeTable',
                                loadMask: true,
                                stripeRows: true,
                                columnLines: true,
                                forceFit: true, //表格自适应
                                columns: [{
                                    header: '采用',
                                    dataIndex: 'paramName',
                                    editor: 'textfield',
                                    align: 'center',
                                    style: 'background: #EEEEEE'
                                }, {
                                    header: '年份',
                                    dataIndex: 'paramValue',
                                    editor: 'textfield',
                                    align: 'center',
                                    style: 'background: #EEEEEE'
                                }, {
                                    header: '方案名',
                                    dataIndex: 'paramExplain',
                                    editor: 'textfield',
                                    align: 'center',
                                    style: 'background: #EEEEEE'
                                }, {
                                    header: '单位',
                                    dataIndex: 'unit',
                                    editor: 'textfield',
                                    align: 'center',
                                    style: 'background: #EEEEEE'
                                }, {
                                    header: '操作',
                                    dataIndex: 'operation',
                                    editor: 'textfield',
                                    align: 'center',
                                    style: 'background: #EEEEEE'
                                }],
                                store: {
                                    fields: ['paramName', 'paramValue', 'paramExplain', 'unit', 'operation'],
                                    data: [
                                        {
                                            paramName: '√',
                                            paramValue: '2016',
                                            paramExplain: '预报方案1',
                                            unit: '水文局',
                                            operation: ' '
                                        }, {
                                            paramName: ' ',
                                            paramValue: '2017',
                                            paramExplain: '预报方案2',
                                            unit: '水文局',
                                            operation: ' '
                                        }
                                    ]
                                }//store
                            }]
                        }]
                    }, {
                        title: '文件',
                        items: [{
                            xtype: 'panel',
                            bodyStyle: 'height:20%;',
                            layout:'column',
                            items: [{
                                height: 500,
                                columnWidth: 0.7,
                                html: '<div class="col-md-12"><form class="form-search">' +
                                '<table class="table"> ' +
                                '<thead><tr><td>请选择上传文件：</td></tr></thead>' +
                                '<tr><td><input type="text" class="input-medium search-query"></td>' +
                                '</tr>' +
                                '</table>' +
                                '</form>' +
                                '</div>'
                            }, {
                                xtype:'button',
                                margin: '35 0 0 0',
                                text: 'Browse',
                                renderTo: Ext.getBody(),
                                columnWidth: 0.28
                            }]
                        }]
                    }]
                }]
            }]
        }]
    }, {
        flex: 3,
        margin: '0 5 0 10',
        xtype: 'runoffTabPanel'
    }],
    listeners: {
        afterrender: 'initData',
        resize: 'bindCalBtnListener',
        show: 'bindCalBtnListener'
    }
});
